package net.getbang.admin.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import net.getbang.admin.entity.SysRole;
import net.getbang.admin.mapper.SysRoleMapper;
import net.getbang.admin.service.SysRoleMenuService;
import net.getbang.admin.service.SysRoleService;

@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper,SysRole> implements SysRoleService{

	@Autowired
	private SysRoleMenuService sysRoleMenuService;
	@Override
	public void update(SysRole role) {
		// TODO 角色更新
		this.baseMapper.updateById(role);
		
		//更新角色与菜单关系
		sysRoleMenuService.saveOrUpdate(role.getId(), role.getMenuIdList());
		
		
	}
	@Override
	@Transactional
	public void save(SysRole role) {
		// TODO Auto-generated method stub
		role.setCreateTime(new Date());
		this.baseMapper.insert(role);
		//保存角色与菜单关系
		sysRoleMenuService.saveOrUpdate(role.getId(), role.getMenuIdList());
	}

}
